/**
 * @author lijuan wang
 * CallGraph contains nodes and edges
 */
package com.ss.cg;

import java.util.ArrayList;
import java.util.List;

public class CallGraph {
		
		
		private String name;

		
		private List<CallGraphNode> nodes;

		
		private List<CallSite> edges;

		
		public String getName() {
			if(name==null||name.equals("")){
				name="test";
			}
			return name;
		}
		
		public void setName(String name) {
			this.name = name;
		}
		
		public List<CallGraphNode> getNodes() {
			return nodes;
		}
		
		public void setNodes(List<CallGraphNode> nodes) {
			this.nodes = nodes;
		}
		
		public List<CallSite> getEges() {
			return edges;
		}
		
		public void setEges(List<CallSite> eges) {
			this.edges = eges;
		}
		
		public CallGraph() {
			this.nodes = new ArrayList<CallGraphNode>();
			this.edges = new ArrayList<CallSite>();
		}
		
		public void addNode(CallGraphNode node) {
			this.nodes.add(node);
		}
		
		public void addEge(CallSite ege) {
			this.edges.add(ege);
		}
		/**
		 * search CallGraphNode
		 * @param identifier
		 */
		public CallGraphNode Search(String identifier){
			CallGraphNode cg=null;
			for(CallGraphNode cgn:this.nodes){
				if(cgn.getIdentifier().equals(identifier)){
					cg=cgn;
					break;
				}
			}
			return cg;
		}
		
		public List<CallGraphNode> getAllCallees(CallGraphNode node){
			List<CallGraphNode> nodes=new ArrayList<CallGraphNode>();
			for(CallSite site:this.edges){
				if(site.getCaller().getId()==node.getId()){
					nodes.add(site.getCallee());
				}
			}
			return nodes;
		}

}
